Ext.define('Hi.view.login.VFormLogin', {
    extend: 'Ext.form.Panel',
    id: 'formLogin',
    title: 'Ingreso Módulo de consultas',
    defaultType: 'textfield',
    bodyStyle: 'padding: 10px;',
    iconCls: 'key',
    collapsible: true,
    frame: true,      
    width: 300,    
    items: [
        {            
            fieldLabel: 'Usuario',
            name: 'user',
            allowBlank: false
        },
        {
            fieldLabel: 'Contraseña',
            name: 'pass',
            inputType: 'password',
            allowBlank: false
        }        
    ],
   
    buttons: [
               {
            text: 'Cancelar',
            handler: function(){
                var extform = this.up('form');
                var form = extform.getForm();
                form.reset();
            }
        },
        {
            text: 'Ingresar',
            id: 'btnIn',
            handler: function(){
                var form = this.up('form');
                form.login();
            }
        }        
    ],
    login: function(){         
        var extform = Ext.getCmp('formLogin');                
        var form = extform.getForm();                        
        if(form.isValid()){
            form.submit({
                url: '/login/login',
                success: function(form, action){
                    if(action.result.login){
//                        document.location = '/Dashboard'                                
                        document.location = '/module'                                
                    }else{
                        Ext.Msg.show({
                            title: 'Acceso Denegado',
                            msg: 'Los datos de autenticación no pudieron ser validados',
                            icon: Ext.Msg.ERROR,
                            buttons: Ext.Msg.OK
                        });
                    }
                },
                failure: function(form, action){

                }
            });

        }
    },
    listeners: {
                afterRender: function(thisForm, options){
                    Ext.get('formLogin').on('keydown', function(e){
                        if(e.getKey() == 13){
                            this.login();
                        }
                    }, this);
                }
            }
});
